<?php
include(WEIXIN_ROBOT_PLUGIN_DIR.'admin/includes/class-weixin-reply-setting.php');
include(WEIXIN_ROBOT_PLUGIN_DIR.'admin/includes/class-weixin-menu.php');

add_action('wpjam_weixin_menu_tabs', function($tabs){
	$tabs =  [
		'menu'			=> ['title'=>'默认菜单',		'function'=>'list',	'list_table_name'=>'weixin-menu-button'],
		'conditional'	=> ['title'=>'个性化菜单',	'function'=>'list',	'list_table_name'=>'weixin-menu']
	];

	if(weixin_get_type() == 2){
		unset($tabs['conditional']);
	}elseif(isset($_GET['tab']) && $_GET['tab'] == 'buttons' && !empty($_GET['menu_id'])){
		if($menu = WEIXIN_Menu::get($_GET['menu_id'])){
			$tabs['buttons']	= ['title'=>$menu['name']?:$menu['menuid'],	'function'=>'list',	'list_table_name'=>'weixin-menu-button', 'args'=>['id'=>$_GET['menu_id']]];
		}else{
			wp_die('该菜单不存在');
		}
	}

	return $tabs;
});

add_filter('wpjam_weixin_menu_button_list_table', function(){

	$style = '
	th.column-name{width:240px;}
	th.column-position{width:70px;}
	th.column-type{width:84px;}
	.tablenav{display:none;}
	.row-actions .dashicons{font-size:16px; line-height:18px;}
	';

	return [
		'title'				=> (weixin_get_type() >= 3)?'默认菜单':'自定义菜单',
		'singular'			=> 'weixin-button',
		'plural'			=> 'weixin-buttons',
		'primary_column'	=> 'name',
		'primary_key'		=> 'pos',
		'model'				=> 'WEIXIN_MenuButton',
		'style'				=> $style,
		'ajax'				=> true,
	];
});

add_filter('wpjam_weixin_menu_list_table', function(){
	$style = '
	th.column-name{width:180px;}
	th.column-menuid{width:100px;}
	.tablenav{display:none;}
	';

	return [
		'title'				=> '个性化菜单',
		'singular'			=> 'weixin-menu',
		'plural'			=> 'weixin-menus',
		'primary_column'	=> 'name',
		'model'				=> 'WEIXIN_Menu',
		'style'				=> $style,
		'ajax'				=> true,
	];
});
